# -*- coding:utf-8 -*-
import json
import re

"""
@Time : 
@Author: 
@Des: 
"""


class QueryWrapper():
    def __init__(self, qw):
        self.queryWrapper = qw

    def gen_where(self):
        return self.queryWrapper

    @staticmethod
    def build_query_wrapper(filter: str, op: str) -> dict:
        f = json.loads(filter)
        o = json.loads(op)
        # print("~~~~~~~~~~~~~~~~~~~~~~~~~~~", f, 0)

        qw = {}

        for k in f:
            if re.match(r'^[a-z0-9_]+$', k) is None:  # or o.get(k,None)==None:
                return {}
            if f[k] != '':
                qw[k] = f[k]
            # qw[k] = {"name":k, "value":f[k], "operator":o[k]}
        return QueryWrapper(qw)
